<template>
    <div class="productVue">
        <div style="width: 100%; height: 40px; display: flex; justify-content: space-between;">
            <input type="text" placeholder="关键字" v-model="keywords" style="flex: 1; height: 40px; border-radius: 5px; border: 1px solid #DCDFE6; padding-left: 10px; font-size: 14px;">
            <div style="width: 70px; height: 40px; border-radius: 5px; background: #2561EF; margin-left: 15px; color: #fff; text-align: center; line-height: 40px; cursor: pointer;" @click="searchFun()">搜索</div>
        </div>
        <div class="product" v-for="(item, index) in list" :key="index"  @click="sendQuestion(item.content)">
            <div class="name">{{ item.title }}</div>
            <div class="content">{{ item.content }}</div>
        </div>
    </div>
</template>

<script>
    import { getReply } from '@/api/msg';
    export default{
        data(){
            return {
                list: [],
                totalPage: 0,
                page: 1,
                limit: 20,
                keywords: ""
            }
        },
        watch: {
            keywords(){
                if(!this.keywords) this.searchFun()
            }
        },
        methods: {
            sendQuestion(content){
                this.$emit("sendQuestion", content)
            },

            searchFun(){
                this.list = []
                this.page = 1
                this.getList()
            },
            getList() {
                const param = {
                    page: this.page,
                    limit: this.limit,
                    keywords: this.keywords
                }
                getReply(param).then((res) => {
                    this.list = this.list.concat(res.list)
                    this.totalPage = res.totalPage;
                    console.log("快捷问题")
                }).catch((err) => {
                    console.log(err)
                });
            },
            getMore(){
                if(this.page>=this.totalPage) return
                this.page ++
                this.getList()
            },
        }
    }
</script>


<style lang="scss" scoped>
    .productVue {
        width: 100%;
        padding: 20px;
        .product {
            width: 100%;
            padding-bottom: 15px;
            border-bottom: 1px solid #f5f5f5;
            margin-top: 15px;
            cursor: pointer;
            .name {
                color: #333;
            }
            .content {
                color: #999;
                padding-top: 10px;
            }
        }
    }
</style>